/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$(function () {
    $("#all_checked").click(function () {
        var src = $("#coll_checkbox").attr("src");
        if (src === "/img/user/checked.png") {
            $("#coll_checkbox").attr("src", "/img/user/checkbox.png");
            $(".coll_checkbox_each").attr("src", "/img/user/checkbox.png");
        } else if (src === "/img/user/checkbox.png") {
            $("#coll_checkbox").attr("src", "/img/user/checked.png");
            $(".coll_checkbox_each").attr("src", "/img/user/checked.png");
        } else {
            $("#coll_checkbox").attr("src", src);
            $(".coll_checkbox_each").attr("src", "/img/user/checked.png");
        }

    });
    $("#coll_checkbox").click(function () {
        var src = $("#coll_checkbox").attr("src");
        if (src === "/img/user/checked.png") {
            $("#coll_checkbox").attr("src", "/img/user/checkbox.png");
            $(".coll_checkbox_each").attr("src", "/img/user/checkbox.png");
        } else if (src === "/img/user/checkbox.png") {
            $("#coll_checkbox").attr("src", "/img/user/checked.png");
            $(".coll_checkbox_each").attr("src", "/img/user/checked.png");
        } else {
            $("#coll_checkbox").attr("src", src);
            $(".coll_checkbox_each").attr("src", "/img/user/checked.png");
        }

    });
    $(".coll_checkbox_each").click(function () {
        var src = $(this).attr("src");
        if (src === "/img/user/checked.png") {
            $(this).attr("src", "/img/user/checkbox.png");
        } else if (src === "/img/user/checkbox.png") {
            $(this).attr("src", "/img/user/checked.png");
        } else {
            $(this).attr("src", "/img/user/checkbox.png");
        }
    });
    $("#cancle_coll").click(function () {
        if (confirm("确定要取消收藏吗?")) {
            var ids = "[";
            $(".coll_checkbox_each").each(function () {
                var src = $(this).attr("src");
                if (src === "/img/user/checked.png") {
                    var cartid = $(this).parent("p").find("#hidden_comid").val();
                    ids += cartid + ",";
                }
            });
            ids += "]";
            if(ids === "[]" || ids.length < 3){
                alert("请选择需要取消收藏的商品或店铺");
                return;
            }
            $.ajax({
            type: "post",
            url: "/deleteUserStore.do",
            timeout: 1000,
            data: {ids: ids},
            dataType: "json",
            cache: false,
            success: function (data) {
                if (data.success) {
                    alert("取消收藏成功!");
                    location.reload(); 
                } else {
                    alert(data.message);
                    
                }
            }
        });
        }

    });
});


